<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.scalar.chiptrack.operations.material.forms.MaterialRequestForm"%>
<%@ page import="com.scalar.chiptrack.operations.material.MaterialRequestLineItem" %>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>
<%@ page import="com.scalar.chiptrack.users.Functionality" %>
<%@ page import="com.scalar.chiptrack.users.User" %>
<%@ page import="com.scalar.chiptrack.commons.SessionKeys" %>
<%@ page import="com.scalar.chiptrack.commons.Constants" %>


<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/materialRequest.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% User user1 = (User)session.getAttribute (SessionKeys.USER_KEY); %>

<html:html locale="true">
<HEAD>
<TITLE>Scalar Soft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<SCRIPT language='javascript'>
function validatefields(){

    formdoc = document.materialRequestForm;
    errMsg = '';
    //formdoc.txtErrMsg.value=errMsg;
	var pa	= document.getElementById("txtErrMsg");//new
    if(alphanumSpecial(formdoc.costCenter.value,'Cost Center','N') == false){  
        
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = '<li> '+errMsg;
        formdoc.costCenter.focus();
        return false;
    }else if(alphanumSpecial(formdoc.internalIssueDepartment.value,'Issuing Department (Int)','N') == false){  
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = '<li> '+errMsg;
        formdoc.internalIssueDepartment.focus();
        return false;
    }else if(alphanumSpecial(formdoc.internalReceivingDepartment.value,'Receiving Department (Int)','N') == false){  
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = '<li> '+errMsg;
        formdoc.internalReceivingDepartment.focus();
        return false;
    }else if(alphanumSpecial(formdoc.externalIssueDepartment.value,'Issuing Department (Ext)','N') == false){  
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = '<li> '+errMsg;
        formdoc.externalIssueDepartment.focus();
        return false;
    }else if(alphanumSpecial(formdoc.externalReceivingDepartment.value,'Receiving Department (Ext)','N') == false){  
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = '<li> '+errMsg;
        formdoc.externalReceivingDepartment.focus();
        return false;
    }else if(alphanumSpecial(formdoc.requestedBy.value,'Requested By','N') == false){  
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = '<li> '+errMsg;
        formdoc.requestedBy.focus();
        return false;
    }else if(chkDate(formdoc.dateNeededBy.value,'Date Needed By','Y') == false){  
        
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = errMsg;
        formdoc.dateNeededBy.focus();
        return false;
    }else if(alphanumSpecial(formdoc.authorizedBy.value,'Authorized By','N') == false){  
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = '<li> '+errMsg;
        formdoc.authorizedBy.focus();
        return false;
    }else if(chkDate(formdoc.authorizedDate.value,'Authorized Date','Y') == false){
        
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = errMsg;
        formdoc.authorizedDate.focus();
        return false;
    }else if(alphanumSpecial(formdoc.requestAuthorizedBy.value,'Requested Authorized By','N') == false){  
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = '<li> '+errMsg;
        formdoc.requestAuthorizedBy.focus();
        return false;
    }else if(chkDate(formdoc.requestAuthorizedByDate.value,'Request Authorized Date','Y') == false){
        
        //formdoc.txtErrMsg.value=errMsg;
		pa.innerHTML = errMsg;
        formdoc.requestAuthorizedByDate.focus();
        return false;
    }else{
       j=0;
       if(count != 0){  // count = 1 means there are no more  Line Items rows.
            if(formdoc.partNumber.value != null){ // conditions works when Line Items row is one

                selectedindex = formdoc.partNumber.options.selectedIndex;
                if(formdoc.partNumber.options[selectedindex].value != -1){
                      intvalue = eval("formdoc.reqQuantity_"+j+".value");
                      if(checkInteger(intvalue,'Requested Quantity in Line No'+eval(j+1),'Y') == false){
                        //formdoc.txtErrMsg.value=errMsg;
						pa.innerHTML = '<li> '+errMsg;
						eval("formdoc.reqQuantity_"+j+".focus()");
                        return false;
                      }
                } 
                if(formdoc.partNumber.options[selectedindex].value != -1){
                      intvalue = eval("formdoc.recQuantity_"+j+".value");
                      if(checkInteger(intvalue,'Received Quantity in Line No'+eval(j+1),'Y') == false){
                        //formdoc.txtErrMsg.value=errMsg;
						pa.innerHTML = '<li> '+errMsg;
                        eval("formdoc.recQuantity_"+j+".focus()");
                        return false;
                      }
                } 
               }else{// conditions works when Line Items rows are more than one
                 while(j < count){ 
                    selectedindex = formdoc.partNumber[j].options.selectedIndex;
                    if(formdoc.partNumber[j].options[selectedindex].value != -1){
                          intvalue = eval("formdoc.reqQuantity_"+j+".value");
                          if(checkInteger(intvalue,'Requested Quantity in Line No'+eval(j+1),'Y') == false){
                            //formdoc.txtErrMsg.value=errMsg;
							pa.innerHTML = '<li> '+errMsg;
                            eval("formdoc.reqQuantity_"+j+".focus()");
                            return false;
                          }
                    } 
                    if(formdoc.partNumber[j].options[selectedindex].value != -1){
                          intvalue = eval("formdoc.recQuantity_"+j+".value");
                          if(checkInteger(intvalue,'Received Quantity in Line No'+eval(j+1),'Y') == false){
                            //formdoc.txtErrMsg.value=errMsg;
							pa.innerHTML = '<li> '+errMsg;
                            eval("formdoc.recQuantity_"+j+".focus()");
                            return false;
                          }
                    } 
                  j++;
                }     // while loop
              }    // if else condtion...    
           } // if condition... condition occurs when no more Line Itmes
     }  // if codition... main if else condition
      
    
    //formdoc.txtErrMsg.value=errMsg;
	pa.innerHTML = errMsg;
    return true;
}
function insertMaterialRequest()
{
    success = true;
    success = validatefields();
    if(success == true){
        document.materialRequestForm.action="<%=chipTracContext%>/materialRequest.do?action=insert";
        document.materialRequestForm.submit();
    }
}
function updateMaterialRequest()
{
    success = true;
    success = validatefields();
    if(success == true){
        document.materialRequestForm.action="<%=chipTracContext%>/materialRequest.do?action=update";
        document.materialRequestForm.submit();
    }    
}
var dateElement = "";
function openCalendar(dateValue)
{
    dateElement = dateValue;
    newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
    newWindow.moveTo(550,180);
    newWindow.focus();
}
function assignDate(passedValue)
{   
dateElement.value=passedValue;
window.focus();
}
</SCRIPT>

<!-- Top Header Start-->

<%@include file="/jsp/includes/header.jsp" %>

<!-- Top Header End-->
 <%  
    String action = ((request.getParameter("action")!=null)?(request.getParameter("action")):"create").trim();
    int count = 0; // count contains what is next line iten number for dynamic display.
     // code the get the Material Request Line Items Linked List
    // this code should only be exectued when action = modify

    java.util.LinkedList lineItemlist = null;
    if ("modify".equalsIgnoreCase(action) == true) {
         try{
         lineItemlist = (java.util.LinkedList)request.getAttribute("lineItemList");
         if(lineItemlist==null) lineItemlist = new java.util.LinkedList();
       }catch(Exception ex){
         lineItemlist = new java.util.LinkedList();  
       }
    }
   // code the get the form Material Request Form data when action = modify.
    MaterialRequestForm materialRequestForm1 = null;    
    String materialRequestNumber = "";
    if ("modify".equalsIgnoreCase(action) == true) {
      try{  
        materialRequestForm1 = (MaterialRequestForm)request.getAttribute("materialRequestForm");
        materialRequestNumber = materialRequestForm1.getMaterialRequestNumber();
       }catch(Exception e){  }
    }    
        
 %>

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->
<%@include file="/jsp/operations/operations_menu.jsp" %></TD>
<!-- end of the side navigations -->

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD valign="top" width="100%"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR><BR><!--<BR><BR><BR><BR>-->

<!-- from here your body starts -->
<center><span class="NArialW">Materials Transfer Request and Authorization</span></center>

<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>

<table border="0" width="95%" align=right cellspacing='3'>
 <!--Bhaskar added this scriptlet on 16 july 2003 enable a blue message to be displayed.-->
 <% if ( !user1.isActionAllowed ( Functionality.MATERIAL_REQUEST, 
 User.USER_ACTION_MODIFY ) ) { %>
    <tr><td colspan='5'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></font></b></td></tr>
<% } %>    
<html:form name="materialRequestForm" action="/materialRequest" method="post" type="com.scalar.chiptrack.operations.material.forms.MaterialRequestForm" focus="internalIssueDepartment">
<html:hidden name="materialRequestForm" property="materialRequestId"  />
<html:hidden name="materialRequestForm" property="materialRequestNumber" /> 
   <!--TR>
        <TD colspan='4' width='100%' align='left'>
            <INPUT align=left border=0 maxLength=100 name="txtErrMsg" size=100 
           style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly>
        </TD>
   </TR-->

   <tr><td colspan='4' align="left" class='NArialL'><FONT id="txtErrMsg" size="-2" color='FF0000'></font></td></tr>

       <% if ("modify".equalsIgnoreCase(action) == true) { %> 
       <tr>
       <td width="21%" align='left'><font class="NArialL">Materials Request Number :</font></td>
       <td width="21%" align='left'><font class="NArialL"><%=materialRequestNumber%></font></td>
       <td width="21%">&nbsp;</TD>
       <TD width="21%">&nbsp;</TD>
       </tr>
       <% } else { %>
          
       <% } %>
       
    <tr>
       <td width="21%"><font class="NArialL">Issuing Department (Int):</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="internalIssueDepartment" styleClass="txfield" size="23" maxlength="50"/></td>
       <!--td width="3%">&nbsp;</td-->
       <td width="21%"><font class="NArialL">Receiving Department (Int):</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="internalReceivingDepartment" styleClass="txfield" size="23" maxlength="50"/></td>
       <!--td width="3%">&nbsp;a</td-->
    </tr>
    <tr>
       <td width="21%"><font class="NArialL">Issuing Department (Ext):</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="externalIssueDepartment" styleClass="txfield" size="23" maxlength="50"/></td>
       <td width="21%"><font class="NArialL">Receiving Department (Ext):</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="externalReceivingDepartment" styleClass="txfield" size="23" maxlength="50"/></td>
    </tr>
    <tr>
    <td width="21%"><font class="NArialL">Cost Center :</font></td>
    <td width="21%"><html:text name="materialRequestForm" property="costCenter" size="23" styleClass="txfield" maxlength="50"/></td>
    <td width="21%">&nbsp;</td>
    <td width="21%">&nbsp;</td>
    </tr>
    
         <tr>
       <td width="21%"><font class="NArialL">Requested By:</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="requestedBy" size="23" styleClass="txfield" /></td>
       <!--td width="3%">&nbsp;a</td-->
       <td width="21%"><font class="NArialL">Date Needed By :<font color=red>*</font></font></td>
        <td width="20%"><font class="NArialL">
        <html:text name="materialRequestForm" property="dateNeededBy" size="20" maxlength='10' styleClass="txfield" />
           </font>&nbsp;
            <a href="javascript:openCalendar(document.materialRequestForm.dateNeededBy)" onMouseOver="window.status='Click to Select Date';return true" onMouseOut="window.status='';return true">
             <img src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20 border="0"></a></td>
        <!--td width="21%"><input type="text" name="dateNeededBy" size="20" class="txfield"></td-->
       <!--td width="3%">&nbsp;a</td-->
       </tr>
     <tr>
      <td width="21%"><font class="NArialL">Authorized by:</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="authorizedBy" size="23" styleClass="txfield"/></td>
       <!--td width="3%">&nbsp;a</td-->
      <td width="21%"><font class="NArialL">Authorized Date :<font color=red>*</font></font></td>
      <td width="20%"><font class="NArialL">
        <html:text name="materialRequestForm" property="authorizedDate" size="20" maxlength='10' styleClass="txfield" />
      	</font>&nbsp;
		<a href="javascript:openCalendar(document.materialRequestForm.authorizedDate)" onMouseOver="window.status='Click to Select Date';return true" onMouseOut="window.status='';return true">
		<img src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20 border="0"></a></td>
       <!--td width="21%"><input type="text" name="authorizedDate" size="20" class="txfield"></td Bhaskar-->
       <!--td width="3%">&nbsp;a</td-->
       </tr>
       <tr>
       <td width="21%"><font class="NArialL">Request Authorized By:</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="requestAuthorizedBy" size="23" styleClass="txfield" /></td>
       <!--td width="3%">&nbsp;a</td-->
     
       <td width="21%"><font class="NArialL">Request Authorized Date:<font color=red>*</font></font></td>
        <td width="20%"><font class="NArialL">
        <html:text name="materialRequestForm" property="requestAuthorizedByDate" size="20" maxlength='10' styleClass="txfield" />
         </font>&nbsp;
	  <a href="javascript:openCalendar(document.materialRequestForm.requestAuthorizedByDate)" onMouseOver="window.status='Click to Select Date';return true" onMouseOut="window.status='';return true">
	   <img src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20 border="0"></a>
        <!--td width="21%"><input type="text" name="requestAuthorizedByDate" size="20" class="txfield"></td-->
       <!--td width="3%">&nbsp;a</td-->
       </td></tr>
       <tr>
        <td width="21%"><font class="NArialL">Description:</font></td></tr>
        <tr>
       <td colspan='4'><html:textarea rows="5" cols="80" name="materialRequestForm" property="description"  styleClass="txfield" disabled="false" /></td>

       <!--td width="3%">&nbsp;a</td-->
     </tr>
     <tr><td width="3%">&nbsp;</td></tr>

      <tr><td colspan='4'>
      <table width='80%' align='left' border='0'>

         <tr>
            <td width="10%" align="center" bgcolor="#993333"><font class="NArialL">
               <font color="#FFFFFF">Line No:</font></td>
            <td width="30%" align="center" bgcolor="#993333"><font class="NArialL">
               <font color="#FFFFFF">Qty Requested:</font></td>
            <td width="30%" align="center" bgcolor="#993333"><font class="NArialL">
               <font color="#FFFFFF">Qty Received:</font></td>
            <td width='30%' align="center" bgcolor="#993333"><font class="NArialL">
                <font color="#FFFFFF"><bean:message key = "label.mfgPartNumber" /></font></td>
          </tr>

          <% 
               count = 0;
                 // action = modify it has to display already avaiable Line Items 
               if ("modify".equalsIgnoreCase(action) == true) {
                
                       java.util.ListIterator lineItemIterator = lineItemlist.listIterator(0);
                       MaterialRequestLineItem materialRequestLineItem = null;
                       while(lineItemIterator.hasNext()){ 
                           materialRequestLineItem = (MaterialRequestLineItem)lineItemIterator.next();
                           if(materialRequestLineItem==null)continue;
                           //lineItemId field is usefully in modify action only. it usefuly to find
                           // how many alredy avaible lineitems are there.
                           //and for new line items the value is "" and for old ones the value
                           // is id generated from the database.
                           
                     %>
                    <tr>
                        <td width="10%" align="center" bgcolor="#DEE1E2">
                        <input type="hidden" name="lineItemId_<%=count%>"  value="<%=materialRequestLineItem.getId()%>" >
                        <input type="text" name="lineItemNo" size="6" value="<%=count+1%>" disabled="disabled" class="txfield"></td>
                        <td width="30%" align="center" bgcolor="#DEE1E2"><font class="NArialL"><font color="#000000">
                        <input type="text" name="reqQuantity_<%=count%>" value="<%=materialRequestLineItem.getRequestQuantity()%>" class="valuetxfield" size='20' maxlength='9'  >
                        </font></td>
                        <td width="30%" align="center" bgcolor="#DEE1E2"><font class="NArialL"><font color="#000000">
                        <input type="text" name="recQuantity_<%=count%>" value="<%=materialRequestLineItem.getReceivedQuantity()%>" class="valuetxfield" size='20' maxlength='9' >
                        </font></td>
                        <td width="30%" align="center" bgcolor="#DEE1E2"><font class="NArialL"><font color="#000000">
                        <html:select  property="partNumber" styleClass="txfield" value="<%=materialRequestLineItem.getPartNumber()%>" >       	   
                        <html:option value="-1">-- Select one --</html:option>
                        <html:options collection="partNumberList" property="value" labelProperty="label"/>
                        </html:select>
                        </font></td>
                   </tr>
                   <%
                    count++;
                     } 
                     if(count == 0){
                         // beacuse in javascript coding purpose count is added by one.
                     // LineItems are zero it has display no line items present
                     %>
                     <tr>
                        <td colspan="4" align="center" bgcolor="#DEE1E2">
                               <font class="NArialL">No Material Request LineItems</font>
                        </td>
                   </tr>
                     <%
                    }
            }  // end of action = modify
            else if ("create".equalsIgnoreCase(action) == true) {
                count = 0;
                while(count<3){ // if action create defintely count of line items = 0;
           %>
               <tr>
                    <td width="10%" align="center" bgcolor="#DEE1E2">
                    <input type="hidden" name="lineItemId_<%=count%>" value="-1" >
                    <input type="text" name="lineItemNo" size="6" value="<%=(count+1)%>" disabled="disabled" class="txfield"></td>
                    <td width="30%" align="center" bgcolor="#DEE1E2"><font class="NArialL"><font color="#000000">
                    <input type="text" name="reqQuantity_<%=count%>"  size='20' maxlength='9' class="valuetxfield">
                    </font></td>
                    <td width="30%" align="center" bgcolor="#DEE1E2"><font class="NArialL"><font color="#000000">
                    <input type="text" name="recQuantity_<%=count%>"  size='20' maxlength='9' class="valuetxfield">
                    </font></td>
                    <td width="30%" align="center" bgcolor="#DEE1E2"><font class="NArialL"><font color="#000000">
                    <html:select property="partNumber" styleClass="txfield" >      	   
                    <html:option value="-1">-- Select one --</html:option>
                    <html:options collection="partNumberList" property="value" labelProperty="label"/>
                    </html:select>
                    </font></td>
                    </tr>
           <%
                count ++;
                } // end of the while loop
            }// end of action = create
            %>
           <tr><td colspan='4' align="left"><FONT id="font1"></FONT></TD></TR> 
           <tr><td colspan='4' align='right'><a href="javascript:addTextArea();" onMouseOver="window.status='Click to Add New Line Item';return true" onMouseOut="window.status='';return true"title="Click here to Add New Line Item">
            <img src="<%=chipTracContext%>/jsp/includes/images/addmore.gif" border=0></a>&nbsp;&nbsp;
        </td></tr>
      </table>
      </td></tr>
       <td colspan=5 align=center>
          <%
            if ("create".equalsIgnoreCase(action) == true) {
          %>
    	  
           <chiptrack:restrictedLink functionality="<%=Functionality.MATERIAL_REQUEST%>" action="<%=User.USER_ACTION_MODIFY%>" href="javascript:insertMaterialRequest();"  onmouseover="window.status='Click to Save Materials Request and Authorization';return true"  onmouseout="window.status=' ';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" title="Click here to Save Materials Request and Authorization"> </chiptrack:restrictedLink>
          <%    
            } else if ("modify".equalsIgnoreCase(action) == true) {
           %>
           <chiptrack:restrictedLink functionality="<%=Functionality.MATERIAL_REQUEST%>" action="<%=User.USER_ACTION_MODIFY%>" href="javascript:updateMaterialRequest();"  onmouseover="window.status='Click to Update Materials Request and Authorization';return true"  onmouseout="window.status=' ';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" title="Click here to Update Materials Request and Authorization" > </chiptrack:restrictedLink>
          
          <%
            }
          %>
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <a href="javascript:document.materialRequestForm.reset();" onMouseOver="window.status='Click to Reset';return true" onMouseOut="window.status='';return true" title="Click here to Reset"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <chiptrack:restrictedLink functionality='<%=Functionality.MATERIAL_REQUEST%>'  href="/chiptrack/materialRequest.do" onmouseover="window.status='Click to Cancel and go Back to Search Screen ';return true" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" title="Click here to Cancel and go Back to Search Screen"> </chiptrack:restrictedLink>
      </td>
      </tr>
     </table>
</html:form>

<!--<BR><BR><BR>--></TD></TR>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->

<%@include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->
<SCRIPT language='javascript'>
// script to add new rows.
// this is place down because to maintain .. no of line items up to now it has.
var count = <%=count%>;
function addTextArea() 
{ 
    var htmltext = '<div><table border="0" width="100%"><tr ><td width="10%" align="center" bgcolor="#DEE1E2">';
    htmltext = htmltext + '<input type="hidden" name="lineItemId_'+count + '"  value="-1" >';
    htmltext = htmltext + '<input type="text" name="lineItemNo" value="'+(count+1)+'" size=6 class="txfield" disabled="true"></td>';        
    htmltext = htmltext + '<td width="30%" align="center" bgcolor="#DEE1E2">';
    htmltext = htmltext + '<input type="text"  name="reqQuantity_'+count + '" maxlength=9 size=20 class="valuetxfield" ></td>';                
    htmltext = htmltext + '<td width="30%" align="center" bgcolor="#DEE1E2">';
    htmltext = htmltext + '<input type="text" name="recQuantity_'+count + '" maxlength=9 size=20 class="valuetxfield"></td>';  
    htmltext = htmltext + '<td width="30%" align="center" bgcolor="#DEE1E2">';
    htmltext = htmltext + '<select name="partNumber" class="txfield"><option value="-1">-- Select one --</option>';
    
    <%
  // code the get the option values of the PartNumbers 
  // required during dymanic added of Line Items

     java.util.ArrayList optionlist = null;

     try{
         optionlist = (java.util.ArrayList)request.getAttribute("partNumberList");
         if(optionlist==null) optionlist = new java.util.ArrayList();
         int optionlistsize = optionlist.size();
         StringBuffer strBuffer = new StringBuffer();
         org.apache.struts.util.LabelValueBean option = null;

         for(int listcount=0;listcount<optionlistsize;listcount++){
            try{

                option = (org.apache.struts.util.LabelValueBean)optionlist.get(listcount);
                strBuffer.append("htmltext = htmltext + '");
                strBuffer.append("<option value=\"").append(option.getValue()).append("\">");
                strBuffer.append(option.getLabel()).append("</option>';\n");

            }catch(Exception e){
                // nothing just ignore the part number --- verify
            }   
          }

          out.println(strBuffer.toString());

        }catch(Exception ex){
       }
    %>

    htmltext = htmltext + '</select></td></tr></table></div>';
    //alert(htmltext);
    var pa=document.getElementById("font1");
    pa.insertAdjacentHTML('BeforeEnd',htmltext);
    count = count+1;
    
    } // end of addtextarea()

</SCRIPT>
</BODY>
</html:html>